package Adapter;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import InterFaceIModel.IQuanLiNo;
import ViewHoder.NoHoder;
import android.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class QuanLiNoAdapter extends ArrayAdapter<IQuanLiNo>{

	Context context;
	int layout;
	List<IQuanLiNo>list;
	
	private NoHoder hoder;
	public QuanLiNoAdapter(Context context, int textViewResourceId,
			List<IQuanLiNo> objects) {
		super(context, textViewResourceId, objects);
		// TODO Auto-generated constructor stub
		this.context=context;
		this.layout=textViewResourceId;
		this.list=objects;
		
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
if (convertView==null) {
			
			LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView=inflater.inflate(layout, parent, false);
			hoder=new NoHoder();
			hoder.txtHoten=(TextView) convertView.findViewById(com.example.quanlithuchi.R.id.txtHoten);
			hoder.txtSotien=(TextView) convertView.findViewById(com.example.quanlithuchi.R.id.txtSotien);
			hoder.txtNgayVay=(TextView) convertView.findViewById(com.example.quanlithuchi.R.id.txtNgayvay);
			hoder.txtNgayTra=(TextView) convertView.findViewById(com.example.quanlithuchi.R.id.txtNgayTra);
			hoder.btnDelete=(ImageView) convertView.findViewById(com.example.quanlithuchi.R.id.image_delete);
			
			hoder.btnEdit=(ImageView) convertView.findViewById(com.example.quanlithuchi.R.id.image_Edit_No);
			
			convertView.setTag(hoder);
		}
		else {
			hoder=(NoHoder) convertView.getTag();
		}
      IQuanLiNo quanLiNo=list.get(position);
        hoder.btnDelete.setTag(quanLiNo);
		hoder.txtHoten.setText(quanLiNo.getHoTen());
		hoder.txtSotien.setText(String.valueOf(quanLiNo.getTienNo()));
		Date ngayno=new Date(quanLiNo.getNgayNo());
		SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
		String ngaynoString = formatter.format(ngayno);
		Date ngaytra=new Date(quanLiNo.getNgaytra());
		String ngaytraString=formatter.format(ngaytra);
		hoder.txtNgayVay.setText(ngaynoString);
		hoder.txtNgayTra.setText(ngaytraString);
		convertView.setPadding(10, 10, 10, 10);
		return convertView;
	}
   
}
